<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <ui:composition template="/template_bill.xhtml"
                    >
        <ui:define name="title">
            <h:outputText value="الفاتورة "></h:outputText>
        </ui:define>
        <ui:define name="body">
            <center><h1> فواتير الموردين</h1></center>
            <h:outputScript name="js/print.js" />
            <!-- start of the photos bar -->
            <h:form>
                <p:growl id="growl" showDetail="true" sticky="true" />
                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <ul class="thumbnails">
                    <li class="span3">
                        <p:commandLink update=":myform:itemID" action="#{billExporterInformationController.meat}" value="لحوم" styleClass="button" > 
                            <p:graphicImage value="img/meat.jpg" />
                        </p:commandLink>
                    </li>
                    <li class="span3">
                        <p:commandLink  update=":myform:itemID" action="#{billExporterInformationController.nonMeat}" value="غير لحوم " styleClass="button1"> 
                            <img src="img/notmeat.jpg" width="220" height="80" title="غير لحوم"/>
                        </p:commandLink>
                    </li>
                    <li class="span3">
                        <p:commandLink update=":myform:itemID" action="#{billExporterInformationController.checken}" value="فراخ" styleClass="button2"> 
                            <img src="img/chicken.jpg" width="220" height="80"  title="فراخ"/>
                        </p:commandLink>

                    </li>
                    <li class="span3">
                        <p:commandLink update=":myform:itemID" action="#{billExporterInformationController.vegtable}" value="منتجات زراعية " styleClass="button3"> 
                            <img src="img/beans.jpg" width="220" height="80" title="منتجات زراعية"/>
                        </p:commandLink>

                    </li>
                </ul>

            </h:form>
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>



            <div class="clear"></div>
            <!-- Customer Information  -->
            <h:form id="myform">
                <div id="Bill">

                    <div class="form-inline well">





                        <label style="padding-left: 10px;" for="input04">رقم الفاتوره</label>
                        <h:inputText size="5" value="#{billExporterInformationController.billNumber}" id="input04" required="true" >
                            <f:ajax execute="@form"  event="change" listener="#{billInformationController.itemListener}"/>

                        </h:inputText>
                        <label style="padding-right: 20px;" for="input04">رقم الدفتر </label>
                        <h:inputText size="5" value="#{billExporterInformationController.docNumber}" required="true" >
                            <f:ajax execute="@form"  event="change" listener="#{billInformationController.itemListener}" />

                        </h:inputText>
                        <label style="padding-right: 10px; " for="input05">التاريخ:</label>
                        <p:calendar value="#{billExporterInformationController.billDate}" id="startDate" showOn="button" pattern="dd/MM/yyyy" >
                            <f:ajax execute="@form"  event="change" listener="#{billInformationController.itemListener}"/>


                        </p:calendar>
                        <div class="clear"></div>
                        <center>
                            <label style="padding-left: 15px;" for="input06">اسم المورد</label>
                            <p:autoComplete  value="#{billExporterInformationController.exporterName}" completeMethod="#{billExporterInformationController.autocomplete}" >
                                <f:ajax render="Exporter" listener="#{billExporterInformationController.itemListener}" event="blur" />
                            </p:autoComplete>


                            <h:panelGroup   id="Exporter" >
                                <label style="padding-left: 15px;padding-right: 20px;" for="input06">الرصيد</label>        

                                <label style="padding-left: 15px;" ></label>
                                <h:panelGroup rendered="#{(billExporterInformationController.selectedExporter.balance > 0)}">
                                    <span class="label label-info" >    
                                        #{billExporterInformationController.selectedExporter.balance}
                                    </span>
                                    لينا 
                                </h:panelGroup>
                                <h:panelGroup rendered="#{ !(billExporterInformationController.selectedExporter.balance > 0)}">
                                    <span class="label label-info" >    
                                        #{billExporterInformationController.selectedExporter.balance*-1}
                                    </span>
                                    مدين 
                                </h:panelGroup>


                            </h:panelGroup>

                        </center>
                    </div>

                </div>

                <!-- start of the add form -->
                <div class="form-inline well">
                    <label style="padding-right: 50px; padding-left: 10px;" for="itemID">المنتج</label>
                    <h:selectOneMenu id="itemID"  value="#{billExporterInformationController.selectedsubItem}" title="SubItem"  valueChangeListener="#{billExporterInformationController.listenItemchanged}" immediate="true" class="chosen">
                        <f:selectItems value="#{billExporterInformationController.items}"/>
                        <f:ajax render="countryID" listener="#{billExporterInformationController.itemListener}" event="valueChange" />
                    </h:selectOneMenu>



                    <label style="padding: 10px;" for="countryID">البلد</label>
                    <h:selectOneMenu id="countryID" value="#{billExporterInformationController.selectedCountry}" title="SubItem" class="chosen" >
                        <f:selectItems value="#{billExporterInformationController.countries}"/>
                        <f:ajax render="factoryID" listener="#{billExporterInformationController.itemListener}" event="valueChange" />
                    </h:selectOneMenu>


                    <label style="padding: 10px;" for="factoryID">المصنع</label>
                    <h:selectOneMenu id="factoryID" value="#{billExporterInformationController.factory}" title="factory" class="chosen">
                        <f:selectItems value="#{billExporterInformationController.facoris}"/>
                    </h:selectOneMenu>
                    <div class="clear"></div>
                    <label style="padding: 10px;" for="input02">العدد</label>
                    <h:inputText size="10" value="#{billExporterInformationController.total_Number}" id="input01"/>
                    <label style="padding-right:10px; padding-left: 10px;" for="input01">الوزن</label>

                    <h:inputText size="10" value="#{billExporterInformationController.totalKg}" id ="input02" />
                    <h:commandButton value="احسب " action="#{billExporterInformationController.calculate}"  />
                    <h:panelGroup    rendered="${limits==0}">
                        <label style="padding: 10px;" for="input03">سعر الوحده</label>
                        <h:inputText size="10" value="#{billExporterInformationController.unite_price}" id="input03" >
                            <f:ajax execute="@form" render="totalprice" event="blur" listener="#{billExporterInformationController.itemListener}"/>
                        </h:inputText>
                        <center>
                            <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">  
                                <h:outputText value="حالة المنتج" />
                                <p:selectOneRadio  id="itemStatus" value="#{billExporterInformationController.billItemStatus}" >  
                                    <f:selectItem itemValue="Regular" itemLabel="عادى"/>
                                    <f:selectItem itemValue="ProductExecution" itemLabel="إعدام"/>
                                </p:selectOneRadio>  
                            </h:panelGrid>
                            <label style="padding: 10px;"> الإجمالى</label> 
                            <span class="label label-info">
                                <h:outputText id ="totalprice" value="#{billExporterInformationController.total_price}"/>
                            </span>
                        </center>
                    </h:panelGroup>
                    <div class="clear"></div>
                    <center>
                        <label style="padding-left: 19px;" for="input03">تاريخ الانتهاء</label>
                        <p:calendar id="date" style="padding-left: 45px;" value="#{billExporterInformationController.expDate}"  showOn="button" required="true" requiredMessage="من فضلك أدخل التاريخ"
                                    pattern="dd/MM/yyyy" 
                                    />

                        <div class="clear"></div>
                        <p:commandLink update=":myform2:add_item2,:myform3:tot,:myform3:balanceAfter" value="اضافه" action="#{billExporterInformationController.add_item}" />
                    </center>

                </div>
            </h:form>
            <div id="item">
                <h:form id="myform2">


                    <h:dataTable id="add_item2" value="#{billExporterInformationController.add_Item}" var="added_item"

                                 class="table table-condensed table-striped">


                        <h:column>
                            <f:facet name="header"> المنتج  </f:facet>
                            #{added_item.item}

                        </h:column>

                        <h:column>
                            <f:facet name="header"> المصنع  </f:facet>
                            #{added_item.factory}
                        </h:column>
                        <h:column>
                            <f:facet name="header"> البلد  </f:facet>
                            #{added_item.country}
                        </h:column>
                        <h:column>
                            <f:facet name="header"> انتهاء الصلاحيه  </f:facet>
                            <h:outputText value="#{added_item.expDate}"  >
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>

                        </h:column>
                        <h:column>
                            <f:facet name="header"> العدد  </f:facet>
                            <h:inputText value="#{added_item.item_count}" size="5" rendered="#{added_item.editable}" />
                            <h:outputText value="#{added_item.item_count}" rendered="#{not added_item.editable}" />


                        </h:column>
                        <h:column>
                            <f:facet name="header"> الوزن   </f:facet>
                            <h:inputText value="#{added_item.item_quantity}" size="5" rendered="#{added_item.editable}" />
                            <h:outputText value="#{added_item.item_quantity}" rendered="#{not added_item.editable}" />
                        </h:column>
                        <h:column>
                            <f:facet name="header"> سعر الوحدة  </f:facet>
                            <h:inputText value="#{added_item.unit_price}" size="5" rendered="#{added_item.editable}" />
                            <h:outputText value="#{added_item.unit_price}" rendered="#{not added_item.editable}" />

                        </h:column>

                        <h:column>
                            <f:facet name="header"> الاجمالي   </f:facet>
                            <h:outputText value=" #{added_item.totoal_price}"  />

                        </h:column> 

                        <h:column >
                            <f:facet name="header"> حالة المنتج </f:facet>
                            <h:outputText value="إعدام" rendered="#{added_item.billItemStatus=='ProductExecution' and not added_item.editable}" />
                            <h:outputText value="عادى" rendered="#{added_item.billItemStatus=='Regular' and not added_item.editable}" />
                            <h:outputText value="عادى" rendered="#{added_item.billItemStatus==null and not added_item.editable}" />

                            <p:selectOneRadio  id="itemStatus" value="#{added_item.billItemStatus}" rendered="#{added_item.editable}">  
                                <f:selectItem itemValue="Regular" itemLabel="عادى"/>
                                <f:selectItem itemValue="ProductExecution" itemLabel="إعدام"/> 
                            </p:selectOneRadio>  
                        </h:column>

                        <h:column>
                            <f:facet name="header"></f:facet>
                            <h:commandButton value="تعديل" action="#{billExporterInformationController.editAction(added_item)}" rendered="#{not added_item.editable}" class="btn btn-primary" />
                            <h:commandButton value="حفظ" action="#{billExporterInformationController.saveAction(added_item)}" rendered="#{added_item.editable}" class="btn btn-primary" />
                            <h:commandButton value="مسح" action="#{billExporterInformationController.deleteAction(added_item)}" class="btn btn-primary" />
                        </h:column>
                    </h:dataTable>
                </h:form>

                <div class="clear"></div>
                <div class="form-inline well">

                    <h:form id="myform3">
                        <label style="padding-right:10px; padding-left: 10px;" for="tot">الاجمالى   </label> 
                        <h:inputText size="10" value="#{billExporterInformationController.billTotal}" id="tot" readonly="true"/>

                        <label style="padding-right:10px; padding-left: 10px;" for="pay">المبلغ المدفوع </label>
                        <h:inputText size="10" value="#{billExporterInformationController.paied}" id="pay">
                            <f:ajax execute="@form" render="rem balanceAfter" event="blur" listener="#{billExporterInformationController.itemListener}"/>
                        </h:inputText>
                        <label style="padding-right:10px; padding-left: 10px;" for="rem">الباقى    </label> 
                        <h:inputText size="10" value="#{billExporterInformationController.bill_reminder}" id="rem" readonly="true"/>


                        <div class="clear"></div>

                        <label style="padding-right:10px; padding-left: 10px;" for="disc">الخصم  </label>
                        <h:inputText size="10" value="#{billExporterInformationController.discount}" id="disc">
                            <f:ajax execute="@form" render="tot rem balanceAfter" event="blur" listener="#{billExporterInformationController.itemListener}"/>
                        </h:inputText>
                        <h:selectBooleanCheckbox value="#{billExporterInformationController.noExistence}" id="non"></h:selectBooleanCheckbox>

                        <label style="padding-right:10px; padding-left: 10px;" for="non">تالف  </label> 
                        <h:panelGroup id ="balanceAfter">
                            <label style="padding-left: 15px;padding-right: 20px;" for="input06">الرصيد بعد الفاتوره</label>        

                            <label style="padding-left: 15px;" ></label>
                            <h:panelGroup rendered="#{billExporterInformationController.balanceAfterBill > 0}">
                                <span class="label label-info" >   
                                    <h:outputText  value="#{billExporterInformationController.balanceAfterBill}"/>

                                </span>
                                لينا

                            </h:panelGroup>
                            <h:panelGroup rendered="#{! (billExporterInformationController.balanceAfterBill > 0)}">
                                <span class="label label-info" >   
                                    <h:outputText  value="#{billExporterInformationController.balanceAfterBill*-1}"/>

                                </span>
                                مدين                        
                            </h:panelGroup>


                        </h:panelGroup>
                        <div class="clear"></div>
                        <center>
                            <h:commandButton value="اطبع " onclick="print('Bill','item')" class="btn btn-primary"/>
                            <h:outputText value=" "/>
                            <h:commandButton value="تم " action="#{billExporterInformationController.commitValues()}" class="btn btn-primary"/>
                            <h:outputText value=" "/>
                            <h:commandButton value="الغاء " action="#{billExporterInformationController.clear()}" class="btn btn-primary"/>

                        </center>
                    </h:form>
                </div>
            </div>   
        </ui:define>
    </ui:composition>
</html>
